package com.c.elmer.util.ftp;

import java.io.DataInputStream;
import java.util.ArrayList;
import java.util.List;

import sun.net.ftp.FtpClient;

public class Sample {

	public static void main(String args[]) throws Exception {
		List list = new ArrayList();
		FtpClient fc;

		String host = "192.168.0.18";

		String path = "";
		String username = "ftpadmin";
		String password = "123456";

		FtpClient client = new FtpClient(host);
		client.login(username, password);
		client.binary();
		client.cd(".");
		
		DataInputStream dis = new DataInputStream(client.list());
		int readCount;
		String s = "";
		while ((s = dis.readLine()) != null) {
			String str = new String(s.replace(" ",	">").getBytes("iso-8859-1"), "gb2312");
			while(str.indexOf(">>") != -1){
				str = str.replace(">>", ">");
			}
			String[] item = str.split(">");
			for(int i=0;i<item.length;i++){
				FtpFileBean bean = new FtpFileBean();
				bean.setSize((long)Double.parseDouble(item[4].toString()));
				bean.setType(item[1]);
				bean.setFilename(item[8]);
				list.add(bean);
			}
			/*
			for(int i=0;i<list.size();i++){
				FtpFileBean bean = (FtpFileBean)list.get(i);
				System.out.println("===bean:"+bean.getSize()+"  "+bean.getFilename()+"  "+bean.getType());
			}*/
		}
		
	}
}